package com.yh.supergo.manager.controller;

import com.yh.supergo.http.HttpResult;
import com.yh.supergo.manager.service.BrandService;
import com.yh.supergo.page.PageResult;
import com.yh.supergo.pojo.Brand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 0715-YuHao
 * @version 1.0
 * @className BrandController
 * @description 控制器
 * @date 2020/11/16 17:27
 */
@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @GetMapping(value = "/{id}")
    public Brand findOne(@PathVariable Long id) {
        return brandService.findOne(id);
    }


    @PostMapping(value = "/query/{page}/{rows}")
    public HttpResult findPage(@RequestBody(required = false)Brand brand,
                               @PathVariable Integer page,
                               @PathVariable Integer rows) {
        try {
            PageResult result = brandService.findPage(page, rows, brand);
            return HttpResult.ok(result);
        }catch (Exception e) {
            e.printStackTrace();
            return HttpResult.error();
        }
    }
}
